﻿using System;
using System.Linq;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(CharacterViewer))]
public class CharacterViewerEditor : Editor
{
	private void ShowCheatMenu(ref bool isActive, string text, Action func)
	{
		isActive = EditorGUILayout.ToggleLeft(text, isActive);
		GUI.enabled = isActive;
		if (func != null)
			func();
		GUI.enabled = true;
	}

	public override void OnInspectorGUI()
	{
		if (EditorApplication.isCompiling)
		{
			EditorGUILayout.LabelField("컴파일 중...");
			
			return;
		}
		
		var inst = target as CharacterViewer;
		

		//EditorGUILayout.LabelField("기본 세팅");
		//EditorGUI.indentLevel++;
		EditorGUILayout.Space();
		inst.playerPrefab = EditorGUILayout.ObjectField("플레이어 프리팝", inst.playerPrefab, typeof(GameObject), true) as GameObject;
		EditorGUILayout.Space();
		inst.enemyPrefab = EditorGUILayout.ObjectField("적 프리팝", inst.enemyPrefab, typeof(GameObject), true) as GameObject;
		//EditorGUI.indentLevel--;
		
		EditorGUILayout.Space();
		if(inst.OriginalCamTrans==null || inst.OriginalCamTrans.Length!=3)
			inst.OriginalCamTrans = new Transform[3];
		inst.OriginalCamTrans[0] = EditorGUILayout.ObjectField("cam1", inst.OriginalCamTrans[0], typeof(Transform), true) as Transform;
		inst.OriginalCamTrans[1] = EditorGUILayout.ObjectField("cam2", inst.OriginalCamTrans[1], typeof(Transform), true) as Transform;
		inst.OriginalCamTrans[2] = EditorGUILayout.ObjectField("cam3", inst.OriginalCamTrans[2], typeof(Transform), true) as Transform;

		EditorGUILayout.Space();

		inst.turnOffSkillCam = EditorGUILayout.ToggleLeft("테이크 카메라 끔", inst.turnOffSkillCam);
		inst.turnOffCamShake = EditorGUILayout.ToggleLeft("카메라 쉐이크 끔", inst.turnOffCamShake);
		EditorGUILayout.Space();
		inst.repeatPlay = EditorGUILayout.ToggleLeft("반복 플레이", inst.repeatPlay);
//		ShowCheatMenu(ref inst.turnOffSkillCam, "테이크 카메라 끔", () =>
//		              {
//			GUI.enabled = true;
//		});
//
//		ShowCheatMenu(ref inst.turnOffSkillCam, "카메라 쉐이크 끔", () =>
//		              {
//			GUI.enabled = true;
//		});

		
		if (GUI.changed)
		{
			serializedObject.ApplyModifiedProperties();
			
			EditorUtility.SetDirty(inst);
		}
		
		Repaint();
	}
}
